/**
 * Created by Administrator on 17-5-8.
 * author@jiangyue
 */

$(function() {
	// 登錄
	$(".please-login-a").on('click',function(e){
		e.preventDefault();
		$(".window-login,.window-login-contant").show();
	});
	// 註冊
	$(".register-btn").on('click',function(e){
		e.preventDefault();
		$(".window-login,.window-register-box").show();
	});
	$(".login-register-s").on('click',function(e){
		e.preventDefault();
		$(".window-register-box").show();
		$(".window-login-contant").hide();
	});
	$(".window-close").on('click',function(e){
		e.preventDefault();
		$(".window-login,.window-login-contant,.window-register-box,.window-forget-pwd").hide();		
	});
	// 忘記密碼
	$(".forget-btn").on('click',function(e){
		e.preventDefault();
		$(".window-login,.window-forget-pwd").show();
	});
	$(".login-forget").on('click',function(e){
		e.preventDefault();
		$(".window-login,.window-forget-pwd").show();
		$(".window-login-contant").hide();
	});
	$(".items li").on('hover',function(){
		$(this).addClass('on').siblings().removeClass('on');
	});
	$('.product-show-cout-lit h3').on('click',function(){
		$(this).siblings('.product-show-cont-box').stop(true,true).slideToggle().parents(".product-show-cout-lit").siblings(".product-show-cout-lit").find('.product-show-cont-box').slideUp();
	});
	$(".question-tit").on('click',function(){
    $(this).toggleClass('active');
		// $(this).toggleClass('active').parents('.question-list').siblings(".question-list").find('h3').removeClass('active');
		// $(this).siblings(".question-cont").stop(true,true).slideToggle().parents(".question-list").siblings(".question-list").find('.question-cont').slideUp();
		$(this).siblings(".question-cont").stop(true,true).slideToggle();
	});
	$(".play-money-btn").on('click',function(e){
		e.preventDefault();
		$(".window-play-money,.window-play-money-box").show();
	});
	$(".play-money-close").on('click',function(){
		$(".window-play-money").hide();
	});
  // 选择银行
  $(".money-info-bankName-top>a").on('click',function(){
    $(this).siblings("ul").stop(true,true).slideToggle();
  });
  $(".money-info-bankName-top ul>li").on('click',function(){
    var txt = $(this).text();
    var nuns = $(this).attr('data-num');
    $(".money-info-bankName-top>a").html(txt);
    $(".hidden-input").val(nuns);
    $(this).parents(".money-info-bankName-top ul").slideUp();
    $(".money-info-info-cont ul").eq($(this).index()).show().siblings().hide();
  });
  // 購買商品添加數量
  $(".plus").on('click',function(){
    var txtNum = parseInt($(".play-number").val());
    $(".play-number").val( parseInt(txtNum) + 1 );  
  });
  $(".reduction").on('click',function(){
    var txtNum = parseInt($(".play-number").val());
    if( txtNum != 1 ){
      $(".play-number").val( parseInt(txtNum) - 1 ); 
    }     
  });
  $(".about-sidebar li>a").on('click',function(e){    
    $(this).parents('li').addClass("on").siblings('li').removeClass('on');
  });
  
  $('a[href*=#],area[href*=#]').click(function() {
    if (location.pathname.replace(/^\//, '') == this.pathname.replace(/^\//, '') && location.hostname == this.hostname) {
        var $target = $(this.hash);
        $target = $target.length && $target || $('[name=' + this.hash.slice(1) + ']');
        if ($target.length) {
            var targetOffset = $target.offset().top;
            $('html,body').stop().animate({
               scrollTop: targetOffset
           }, 800);
            return false;
        }
      }
  }); 

var offsetTop = $(".nav").offset().top;
$(window).scroll(function(){
    if( $(this).scrollTop() > offsetTop){
        $(".nav").css({
            top:0,
            position:"fixed",
            width:"100%", 
            zIndex:999,
            background: '#FFF',
            borderBottom:"1px solid #eaeaea"
        });
        $(".nav>ul").css({
            'width':"1000px",
            'margin':"0 auto",
        });
    }else{
        $(".nav").css({top:'',position:'',borderBottom:"",width:'',zIndex:'',background:''});
        $(".nav>ul").css({width:'',margin:''});
    }   
});
// 首頁新聞
$(".index-new-tab li").on('click',function(){
    $(this).addClass('on').siblings().removeClass('on');
    $(".index-new-list").eq( $(this).index() ).show().siblings().hide();
}).eq(0).click();

  // $(".window-forget-content>ul>li.fix").click(function(){
  //   $(this).next('.index-tips').find('i').show();
  // });
  // $(".window-forget-content>ul>li.fix").blur(function(){
  //   $(this).next('.index-tips').find('i').hide();
  // });


});
// 首頁注冊
// function ShowTip(obj){
//     if( obj.value == '' ){
//         $(obj).parents('li').next('li.index-tips').find('i').show();
//     }
// }
// function hideTip(obj){
//     if( obj.value !== '' ){
//         $(obj).parents('li').next('li.index-tips').find('i').hide();
//     }
// }

//=====================全局函数========================

//==================图片详细页函数=====================
//鼠标经过预览图片函数
function preview(img){
	$("#preview .jqzoom img").attr("src",$(img).attr("src"));
	$("#preview .jqzoom img").attr("jqimg",$(img).attr("bimg"));
}

//图片放大镜效果
$(function(){
	$(".jqzoom").jqueryzoom({xzoom:350,yzoom:350});
});

//图片预览小图移动效果,页面加载时触发
$(function(){
	var tempLength = 0; //临时变量,当前移动的长度
	var viewNum = 5; //设置每次显示图片的个数量
	var moveNum = 2; //每次移动的数量
	var moveTime = 300; //移动速度,毫秒
	var scrollDiv = $(".spec-scroll .items ul"); //进行移动动画的容器
	var scrollItems = $(".spec-scroll .items ul li"); //移动容器里的集合
	var moveLength = scrollItems.eq(0).width() * moveNum; //计算每次移动的长度
	var countLength = (scrollItems.length - viewNum) * scrollItems.eq(0).width(); //计算总长度,总个数*单个长度
	  
	//下一张
	$(".spec-scroll .next").bind("click",function(){
		if(tempLength < countLength){
			if((countLength - tempLength) > moveLength){
				scrollDiv.animate({left:"-=" + moveLength + "px"}, moveTime);
				tempLength += moveLength;
			}else{
				scrollDiv.animate({left:"-=" + (countLength - tempLength) + "px"}, moveTime);
				tempLength += (countLength - tempLength);
			}
		}
	});
	//上一张
	$(".spec-scroll .prev").bind("click",function(){
		if(tempLength > 0){
			if(tempLength > moveLength){
				scrollDiv.animate({left: "+=" + moveLength + "px"}, moveTime);
				tempLength -= moveLength;
			}else{
				scrollDiv.animate({left: "+=" + tempLength + "px"}, moveTime);
				tempLength = 0;
			}
		}
	});
});
//==================图片详细页函数=====================
/**
*  by Mantou qq:676015863
*  数字滚动插件 v1.0
*/
;(function($) {
  $.fn.numberAnimate = function(setting) {
    var defaults = {
      speed : 1000,//动画速度
      num : "", //初始化值
      iniAnimate : true, //是否要初始化动画效果
      symbol : '',//默认的分割符号，千，万，千万
      dot : 0 //保留几位小数点
    }
    //如果setting为空，就取default的值
    var setting = $.extend(defaults, setting);
  
    //如果对象有多个，提示出错
    if($(this).length > 1){
      alert("just only one obj!");
      return;
    }
  
    //如果未设置初始化值。提示出错
    if(setting.num == ""){
      alert("must set a num!");
      return;
    }
    var nHtml = '<div class="mt-number-animate-dom" data-num="{{num}}">\
            <span class="mt-number-animate-span">0</span>\
            <span class="mt-number-animate-span">1</span>\
            <span class="mt-number-animate-span">2</span>\
            <span class="mt-number-animate-span">3</span>\
            <span class="mt-number-animate-span">4</span>\
            <span class="mt-number-animate-span">5</span>\
            <span class="mt-number-animate-span">6</span>\
            <span class="mt-number-animate-span">7</span>\
            <span class="mt-number-animate-span">8</span>\
            <span class="mt-number-animate-span">9</span>\
            <span class="mt-number-animate-span dot-number">.</span>\
          </div>';
  
    //数字处理
    var numToArr = function(num){
      num = parseFloat(num).toFixed(setting.dot);
      if(typeof(num) == 'number'){
        var arrStr = num.toString().split("");  
      }else{
        var arrStr = num.split("");
      }
      //console.log(arrStr);
      return arrStr;
    }
  
    //设置DOM symbol:分割符号
    var setNumDom = function(arrStr){
      var shtml = '<div class="mt-number-animate">';
      for(var i=0,len=arrStr.length; i<len; i++){
        if(i != 0 && (len-i)%3 == 0 && setting.symbol != "" && arrStr[i]!="."){
          shtml += '<div class="mt-number-animate-dot">'+setting.symbol+'</div>'+nHtml.replace("{{num}}",arrStr[i]);
        }else{
          shtml += nHtml.replace("{{num}}",arrStr[i]);
        }
      }
      shtml += '</div>';
      return shtml;
    }
  
    //执行动画
    var runAnimate = function($parent){
      $parent.find(".mt-number-animate-dom").each(function() {
        var num = $(this).attr("data-num");
        num = (num=="."?10:num);
        var spanHei = $(this).height()/11; //11为元素个数
        var thisTop = -num*spanHei+"px";
        if(thisTop != $(this).css("top")){
          if(setting.iniAnimate){
            //HTML5不支持
            if(!window.applicationCache){
              $(this).animate({
                top : thisTop
              }, setting.speed);
            }else{
              $(this).css({
                'transform':'translateY('+thisTop+')',
                '-ms-transform':'translateY('+thisTop+')',   /* IE 9 */
                '-moz-transform':'translateY('+thisTop+')',  /* Firefox */
                '-webkit-transform':'translateY('+thisTop+')', /* Safari 和 Chrome */
                '-o-transform':'translateY('+thisTop+')',
                '-ms-transition':setting.speed/1000+'s',
                '-moz-transition':setting.speed/1000+'s',
                '-webkit-transition':setting.speed/1000+'s',
                '-o-transition':setting.speed/1000+'s',
                'transition':setting.speed/1000+'s'
              }); 
            }
          }else{
            setting.iniAnimate = true;
            $(this).css({
              top : thisTop
            });
          }
        }
      });
    }
  
    //初始化
    var init = function($parent){
      //初始化
      $parent.html(setNumDom(numToArr(setting.num)));
      runAnimate($parent);
    };
  
    //重置参数
    this.resetData = function(num){
      var newArr = numToArr(num);
      var $dom = $(this).find(".mt-number-animate-dom");
      if($dom.length < newArr.length){
        $(this).html(setNumDom(numToArr(num)));
      }else{
        $dom.each(function(index, el) {
          $(this).attr("data-num",newArr[index]);
        });
      }
      runAnimate($(this));
    }
    //init
    init($(this));
    return this;
  }
})(jQuery);

//=============================================================================//